package com.dkm.biz.ou.domain;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.ResourceTransactionManager;

import com.dkm.biz.domain.AbstractDomain;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.biz.ou.persistence.dao.ShopAuthDao;
import com.dkm.biz.ou.persistence.entity.ShopAuthPo;
import com.dkm.biz.ou.persistence.entity.ShopPo;
import com.dkm.biz.ou.persistence.entity.ShopPoEnum;
import com.dkm.biz.ou.persistence.entity.ShopStatPo;
import com.dkm.biz.ou.persistence.entity.ShopStatPoEnum;
import com.dkm.biz.ou.repository.ShopAuthRepository;
import com.dkm.biz.ou.repository.ShopRepository;
import com.dkm.biz.ou.repository.ShopStatRepository;

/**
 * 对象功能:t_ou_shop_auth 领域对象实体
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-07-25 10:59:54
 */
@SuppressWarnings("serial")
@Service
@Scope("prototype")
public class ShopAuth extends AbstractDomain<String, ShopAuthPo>{
	 
	 private ShopAuthDao shopAuthDao = null;
     @Resource
     private ShopAuthRepository shopAuthRepository;
     @Resource
     private ShopStatRepository shopStatRepository;
     @Resource
     private ShopRepository shopRepository;
	 
	protected void init(){
		shopAuthDao = SpringHelper.getBean(ShopAuthDao.class);
		setDao(shopAuthDao);
	}

	public Boolean createAuth(ShopAuthPo shopAuthPo, String shopType) {
		String referralCode = shopAuthPo.getReferralCode();
		boolean falg = true;
	   if(falg){
		   ShopPo shopPo = new ShopPo();
		   shopPo.setType(shopType);
		   shopPo.setPartyId(shopAuthPo.getPartyId());
		   shopPo.setStatus(ShopPoEnum.downline.toString());
		   shopPo.setCreateTime(new Date());
		   Shop shop=  shopRepository.newInstance(shopPo);
		   shop.create();
		   
		    ShopStatPo shopStatPo= new ShopStatPo();
		    shopStatPo.setProductQty(0);
			shopStatPo.setDynamicQty(0);
			shopStatPo.setFollowQty(0);
			shopStatPo.setProductQty(0);
			shopStatPo.setStockQty(0);
		    shopStatPo.setShopId(shop.getId());
		    ShopStat shopStat =shopStatRepository.newInstance(shopStatPo);
		    shopStat.create();
		   
		   shopAuthPo.setShopId(shopPo.getId());
		   ShopAuth shopAuth =	shopAuthRepository.newInstance(shopAuthPo);
		   
		   shopAuth.create();
	   }
	   
		return true;
	}	 
	 
}
